
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.HtmlMacroComponent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Label;
import org.zkoss.zul.Window;
import org.zkoss.zul.api.Datebox;
import org.zkoss.zul.api.Intbox;
import org.zkoss.zul.api.Combobox;

import utilities.utilities_components.PlainList;

public class ClientSearchController extends Window{
	public void showPlainList()
	{
		PlainList pList = new PlainList();
		pList.setId("CLIENT_RESULT_LIST");
		String header[] = {"姓名","房号","性别","出生年月","证件类型","证件编码","来自","登记时间"};
		String footer[] = {"合计","0","人次"};
		pList.setHead(header);
		pList.setFooter(footer, {1,1,1}, {0,2,3}, {0,2});
		pList.setParent((Component)this);
		this.addEventListener("onNotify", new CSListener());
	}
	
	public void ageBoxCheck()throws Exception
	{
		Intbox box1 = (Intbox)getFellow("CS_LOWER_AGE_BOX");
		Intbox box2 = (Intbox)getFellow("CS_HIGHER_AGE_BOX");
		if (box1.getValue() >= box2.getValue())
		{
			box2.setValue(0);
			throw new WrongValueException(box2,"年龄上限应大于下限");
		}
	}
	
	public void dateBoxCheck()throws Exception
	{
		Datebox box1 = (Datebox)getFellow("CS_TIME_FROM_BOX");
		Datebox box2 = (Datebox)getFellow("CS_TIME_TO_BOX");
		if (box1.getValue().compareTo(box2.getValue()) >= 0)
		{
			box2.setValue(null);
			throw new WrongValueException(box2,"起始日期应先于截止日期");
		}
	}
	
	public void fillComboBox()
	{
		String [] items1 = {"单人间","双人间","标准间","套间","三人间","四人间"};
		Combobox resBox = (Combobox)getFellow("CS_SEARCH_RESTRICTION_BOX");
		Combobox roomResBox = (Combobox)getFellow("CS_ROOM_RESTRICTION_BOX");
		if (resBox.getSelectedIndex() == 1)
		{
			int i;
			for(i = 0;i < roomResBox.getItemCount();i++)
				roomResBox.removeItemAtApi(i);
			for (i = 0;i <items1.length;i++)
				roomResBox.appendItemApi(items[i]);	
		}
		else
		{
			int i;
			for(i = 0;i < roomResBox.getItemCount();i++)
				roomResBox.removeItemAtApi(i);
		}
		
	}
	
	public void onSearch()
	{
		setAttribute("list", (PlainList)getFellow("CLIENT_RESULT_LIST"));
		setAttribute("name", ((Textbox)getFellow("CS_NAME_BOX")).getValue());
		setAttribute("ageChecked", ((Checkbox)getFellow("CS_AGE_CHECK")).isChecked());
		setAttribute("low_age", ((Intbox)getFellow("CS_LOWER_AGE_BOX")).getValue());
		setAttribute("high_age", ((Intbox)getFellow("CS_HIGHER_AGE_BOX")).getValue());
		setAttribute("timeFrom", ((Datebox)getFellow("CS_TIME_FORM_BOX")).getValue());
		setAttribute("timeTo", ((Datebox)getFellow("CS_TIME_TO_BOX")).getValue());
		setAttribute("sex", 2);
		if (((Combobox)getFellow("CS_SEX_BOX")).getSelectedIndex() == 0)
			setAttribute("sex", 0);
		else if (((Combobox)getFellow("CS_SEX_BOX")).getSelectedIndex() == 1)
			setAttribute("sex", 1);
		setAttribute("res", ((Combobox)getFellow("CS_SEARCH_RESTRICTION_BOX")).getSelectedItemApi());
		setAttribute("roomRes", ((Combobox)getFellow("CS_ROOM_RESTRICTION_BOX")).getSelectedItemApi());
		
		setAttribute("detail",(Button)getFellow("CS_DETAIL_BUTTON"));
		Events.sendEvent(new Event("onNotify",this));
	}
}
